home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacGambit 2.0 / sources1 / Examples / pi.scm < prev    next >
Encoding:
Text File  |  1992-03-18  |  916 b   |  22 lines  |  [TEXT/gamI]

  1. ; Compute pi
  2.  
  3. (define (square x) (* x x))
  4.  
  5. (define (partial-sum i n e ee base)
  6.   (- (quotient base (* i e))
  7.      (quotient base (* (+ 2 i) ee))))
  8.  
  9. (define (a n base)  ; atan(1/n)
  10.   (do ((i 1 (+ 4 i))
  11.        (delta 1 (partial-sum i n e (* e n n) base))
  12.        (e n (* e n n n n))
  13.        (sum 0 (+ sum delta)))
  14.       ((zero? delta) sum)))
  15.  
  16. (define (calc-pi base)
  17.   (- (* 32 (a  10 base))
  18.      (* 16 (a 515 base))
  19.      (*  4 (a 239 base))))
  20.  
  21. (define (run)
  22.   (display "How many digits of pi do you want (0 to exit):